package com.ywjt.platformbusiness.home.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ywjt.platformbusiness.R;
import com.ywjt.platformbusiness.base.BaseVPFragment;
import com.ywjt.platformbusiness.home.adapter.HomeGoodsFragmentAdapter;

import java.util.ArrayList;
import java.util.List;

public class HomeTypeGoodsFragment extends BaseVPFragment {
    private Context context;
    private List<Integer> banners;
    private RecyclerView rcGoods;
    private HomeGoodsFragmentAdapter goodsAdapter;

    public static HomeTypeGoodsFragment newInstance(String type) {
        Bundle arguments = new Bundle();
        arguments.putString("type",type);
        HomeTypeGoodsFragment fl = new HomeTypeGoodsFragment();
        fl.setArguments(arguments);
        return fl;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.goods_type_fragment,container,false);
        initView(view);
        return view;
    }


    @Override
    protected void onFragmentVisibleChange(boolean isVisible) {

    }


    public void initView(View view){
        context=getActivity();
        rcGoods=view.findViewById(R.id.rcCommon);
        banners=new ArrayList<>();
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);
        banners.add(R.mipmap.icon_classify_banner_img);




        goodsAdapter=new HomeGoodsFragmentAdapter(banners);
        rcGoods.setLayoutManager(new GridLayoutManager(context,2,RecyclerView.VERTICAL,false));
        rcGoods.setAdapter(goodsAdapter);
        goodsAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
            }
        });

    }

    /**
     * 在fragment首次可见时回调，可用于加载数据，防止每次进入都重复加载数据
     */
    @Override
    protected void onFragmentFirstVisible() {

    }
}
